// 导入axios
import axios from "axios";

export default {
  // 开启命名空间
  namespaced: true,
  state: () => ({
    token: "",
    userInfo: {},
  }),
  mutations: {
    updateToken(state, token) {
      state.token = token;
    },
    updateUserInfo(state, userInfo) {
      state.userInfo = userInfo;
    },
  },
  //  异步请求
  actions: {
    async getUserInfo(context) {
      // console.log(context);
      const { data: res } = await axios.get("/my/userinfo");
      //   console.log(res);
      if (res.code !== 0) return
      context.commit("updateUserInfo", res.data);
    },
  },
};

